/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */
var searchRange = function (nums, target) {
  let left = 0,
    right = nums.length,
    ans = nums.length;
  while (left <= right) {
    const mid = (right + left) >> 1;
    if (target <= nums[mid]) {
      right = mid - 1;
      ans = mid;
    } else {
      left = mid + 1;
    }
  }
  let l = ans;
  r = ans;
  while (nums[l] === target) {
    l--;
  }
  while (nums[r] === target) {
    r++;
  }
  return l+1>r-1?[-1,-1]:[l+1, r-1];
};

console.log(searchRange([5,7,7,8,8,10],6))